package com.sans.collection;

import org.junit.Test;

import java.util.*;

/**
 * @author Sans
 */
public class IteratorTest {
    @Test
    public void iterList() {
        List<Integer> num = List.of(1, 1, 4, 5, 1, 4, 4, 3, 9, 6);
        Iterator<Integer> it = num.iterator();
        while (it.hasNext()) {
            System.out.println(it.next());
        }
    }

    @Test
    public void iterSet() {
        Set<Integer> set = new HashSet<>();
        set.add(1);
        set.add(4);
        set.add(7);
        set.add(2);
        set.add(5);
        set.add(8);
        Iterator<Integer> it = set.iterator();
        while (it.hasNext()) {
            System.out.println(it.next());
        }
    }

    @Test
    public void iterMap() {
        Map<String, Object> map = new HashMap<>(10);
        map.put("姓名", "古尔丹");
        map.put("年龄", 108);
        map.put("种族", "兽人");
        Iterator<Map.Entry<String, Object>> it = map.entrySet().iterator();
        while (it.hasNext()) {
            System.out.println(it.next());
        }
    }
}
